package com.xiaohudie.Ioliu;

import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

/**
 * @Author xiao hu die
 * @Date 2022/1/8 17:16
 * @Version 1.0
 */
/**bufferRead*/
public class Test03 {
    public static void main(String[] args) throws  Exception{
        String path ="D:\\people.java";
        BufferedReader bufferedReader = new BufferedReader(new FileReader(path));
        String line ;
        while( (line = bufferedReader.readLine()) !=null){
            System.out.println(line);
        }
        bufferedReader.close();
    }
    @Test
    public void test01() throws  Exception{
        String path= "D:\\ld.txt";
        /**指定为true则为追加的方法*/
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(path,true));
        bufferedWriter.write("你好呀刘碟");
        bufferedWriter.newLine();
        bufferedWriter.write("你好呀,成为以");
        bufferedWriter.newLine();
        bufferedWriter.write("你好呀,龚雪艳");
        bufferedWriter.close();
    }
    /**buffer实现文件拷贝（专门处理字符的）
     * 只能处理文本文件，不能处理二进制文件*/
    @Test
    public void test02() throws Exception{
        String yuanpatH= "D:\\ld.txt";
        String mianpatH ="D:\\ld2.txt";
        BufferedReader bufferedReader =null;
        BufferedWriter bufferedWriter =null;
         bufferedReader = new BufferedReader(new FileReader(yuanpatH));
         bufferedWriter =new BufferedWriter(new FileWriter(mianpatH));
         String line = null;
       while ((line = bufferedReader.readLine())!=null){
           bufferedWriter.write(line);
           bufferedWriter.newLine();
       }
       bufferedReader.close();
       bufferedWriter.close();
    }
}
